package com.example.onlinetaxi.ui.activity.CommentPage;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.onlinetaxi.R;
import com.example.onlinetaxi.dto.CommentDto.CommentDto;
import com.example.onlinetaxi.util.TimeUtil;
import com.iarcuschin.simpleratingbar.SimpleRatingBar;

public class ShowCommentFragment extends Fragment {

    private View rootView;
    // 控件
    private TextView showCommentTitle;
    private TextView showCommentTime;
    private TextView showCommentScore;
    private TextView showCommentContent;
    // 星星条
    private SimpleRatingBar ratingBar;
    // 评论信息
    private CommentDto comment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_show_comment_fragment, container, false);

        initView();

        return rootView;
    }

    private void initView() {
        showCommentTitle = rootView.findViewById(R.id.show_comment_title);
        showCommentTime = rootView.findViewById(R.id.show_comment_time);
        showCommentScore = rootView.findViewById(R.id.show_comment_score);
        showCommentContent = rootView.findViewById(R.id.show_comment_content);
        ratingBar = rootView.findViewById(R.id.show_comment_ratingbar);


        if (comment.getUserType().equals("driver")) {
            showCommentTitle.setText("司机评价");
        } else {
            showCommentTitle.setText("乘客评价");
        }

        showCommentContent.setText(comment.getContent());
        showCommentScore.setText(comment.getScore() + "分");
        ratingBar.setRating(Float.parseFloat(comment.getScore()));
        showCommentTime.setText(TimeUtil.DateToString(comment.getCommentTime()));
    }

    public void setData(CommentDto comment) {
        this.comment = comment;
    }
}